﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;



/// <summary>
/// 该类为MD5加密类
/// </summary>
public class Encrypt
{
    public Encrypt()
    {
    }
    /// <summary>
    /// 静态加密方法
    /// </summary>
    /// <param name="s">需要加密的字符串</param>
    /// <returns>返回一个加密后的字符串</returns>
    public static String toMD5(String s) //把字符串“s”用MD5算法编码
    {
        MD5 md5 = new MD5CryptoServiceProvider();

        byte[] aa = System.Text.Encoding.UTF8.GetBytes(s);

        byte[] res = md5.ComputeHash(aa);

        StringBuilder bb = new StringBuilder();

        for (int i = 0; i < res.Length; i++)
        {
            if (res[i] < 16)
            {
                bb.Append("0");
            }
            bb.Append(res[i].ToString("x"));
        }

        return bb.ToString();

    }

}
